package com.tuanzi.loan.web.bean.miniApps.recommend;

import static com.tuanzi.loan.business.constants.DictionaryCode.API_SERIAL;
import static com.tuanzi.loan.business.constants.DictionaryCode.APPROVAL_TYPE;
import static com.tuanzi.loan.business.constants.DictionaryCode.CREDIT_CARD_TAG;
import static com.tuanzi.loan.business.constants.DictionaryCode.FIRST_PARTY_LOAN_TYPE;
import static com.tuanzi.loan.business.constants.DictionaryCode.IDENTITY_TAG;
import static com.tuanzi.loan.business.constants.DictionaryCode.LOAN_NECESSARY_DATA;
import static com.tuanzi.loan.business.constants.DictionaryCode.LOAN_PRODUCT_REPAY_TYPE;
import static com.tuanzi.loan.business.constants.DictionaryCode.PLATFORM;
import static com.tuanzi.loan.business.constants.DictionaryCode.PROMOTION_TYPE;
import static com.tuanzi.loan.business.constants.DictionaryCode.RATE_TYPE;
import static com.tuanzi.loan.business.constants.DictionaryCode.THIRD_PARTY_LONG_TAG;
import static com.tuanzi.loan.business.constants.DictionaryCode.UNION_INFO;
import static com.tuanzi.loan.business.constants.DictionaryCode.UNION_SERIAL;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;

import lombok.Data;
import lombok.EqualsAndHashCode;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.primefaces.event.FileUploadEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.entity.miniApps.articleLibrary.MiniAppsArticle;
import com.tuanzi.loan.business.service.miniApps.articleLibrary.HealthHeadlineService;
import com.tuanzi.loan.business.service.miniApps.recommend.HealthHeadlineRecommendService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.view.miniApps.MiniAppsRelationVo;
import com.tuanzi.loan.vo.view.miniApps.articleLibrary.MiniAppsArticleUrlVo;
import com.tuanzi.loan.vo.view.miniApps.recommend.HealthHeadlineRecommendInfoView;
import com.tuanzi.loan.web.configuration.JSFInfoBean;

/**
 * @author weibifeng 
 */
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class HealthHeadlineRecommendInfoBean extends JSFInfoBean<HealthHeadlineRecommendInfoView> {
	
    private static final long serialVersionUID = -2152778554108785342L;
    @Autowired
    private HealthHeadlineRecommendService healthHeadlineRecommendService;
    @Autowired
    private HealthHeadlineService headlineService;
    
    private List<MiniAppsArticle> articleList = null; // 推荐文章列表
    private List<MiniAppsRelationVo> advertiseList = null; // 广告位列表
    private List<MiniAppsRelationVo> allMiniAppsList = null; // 小程序列表

    
    @PostConstruct
    private void init() {
        String articleRelationId = getParamFromRequest("articleRelationId");
        if (StringUtils.isNotBlank(articleRelationId)) {
            $ = healthHeadlineRecommendService.loadHealthHeadlineInfoView(NumberUtils.toLong(articleRelationId));
        } else {
            $ = new HealthHeadlineRecommendInfoView();
            changeStatusToAdd();
        } 
        articleList = healthHeadlineRecommendService.getRecommendArticle();
        advertiseList = healthHeadlineRecommendService.getAdvertiseList();
        allMiniAppsList = healthHeadlineRecommendService.getMiniAppsList();
    }
    
    public String onPreview() {
    	return redirect("http://www.baidu.com");
    }
    
    public void onCopyMedia(MiniAppsArticleUrlVo vo) {
//    	$.setCopyMedia(new MiniAppsArticleUrlVo());
//    	BeanUtils.copyProperties(vo, $.getCopyMedia());
    }
    
    public void onUploadContextConfImage(FileUploadEvent event) {
//    	String imgUrl = this.uploadImg(event.getFile());
//    	MiniAppsArticleUrlVo urlVo = healthHeadlineService.saveContentConfImg($, imgUrl);
//    	$.getContentImgList().add(urlVo);
    	addSuccessfullyMessage();
    }
    
    public void onUploadContextConfVideo(FileUploadEvent event) {
//    	String videoUrl = this.uploadImg(event.getFile());
//    	MiniAppsArticleUrlVo urlVo = healthHeadlineService.saveContentConfVideo($, videoUrl);
//    	$.getContentVideoList().add(urlVo);
    	addSuccessfullyMessage();
    }
    
    public void onUploadRecommendMainImage(FileUploadEvent event) {
//    	$.getRecommendMainImage().setUploadUrl(this.uploadImg(event.getFile()));
    }

    public void onSave() {
    	healthHeadlineRecommendService.saveAdvertise($);
        changeStatusToView();
        addSuccessfullyMessage();
    }
    
    public void onSaveOrUpdRegion(){
//    	$.setSelectedRegionNodes(selectedRegionNodes);
//    	ProductInfoView view = productInfoService.saveOrUpdateRegion($);
//    	$.setProductInfoId(view.getProductInfoId());
    }


    public void onUploadBusinessLicense(FileUploadEvent event) {
//        $.setBusinessLicense(this.uploadImg(event.getFile()));
    }

    public void onUploadLogo(FileUploadEvent event) {
//        $.setLogo(this.uploadImg(event.getFile()));
    }

    public void onUploadMarketTag(FileUploadEvent event) {
//        $.setMarketTag(this.uploadImg(event.getFile()));
    }

    @Override
    protected List<String> getDictionaryCodes() {
        return Lists.newArrayList(FIRST_PARTY_LOAN_TYPE, APPROVAL_TYPE, CREDIT_CARD_TAG, IDENTITY_TAG, LOAN_NECESSARY_DATA, PROMOTION_TYPE, RATE_TYPE, UNION_INFO, UNION_SERIAL, API_SERIAL, PLATFORM ,THIRD_PARTY_LONG_TAG,LOAN_PRODUCT_REPAY_TYPE);
    }
    
    

}




